<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/pages/template/general.xhtml">
	
	<ui:define name="content">
		<div class="pageHeader">Solicitações de <h:outputText value="#{solicitacaoSetorBean.usuarioBean.chefeSetor.descricao}" /></div>
		
		<h:form id="viewForm">
			<p:growl autoUpdate="true" showDetail="true" life="3000" />
			
			<p:dataTable id="viewTable" value="#{solicitacaoSetorBean.itens}" var="item"
				paginator="true" rows="10"
				emptyMessage="Você não tem nenhum registro de solicitações.">
				
				<p:column headerText="Código" sortBy="#{item.id}" style="text-align: center;">
					<h:outputText value="#{item.id}" />
				</p:column>
				
				<p:column headerText="Servidor" sortBy="#{item.servidor.matricula}">
					<h:outputText value="#{item.servidor.matricula} - #{item.servidor.nome}" />
				</p:column>
				
				<p:column headerText="Data" sortBy="#{item.dataCadastro}" style="text-align: center;">
					<h:outputText value="#{item.dataCadastro}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText><br />
					<h:outputText value="#{item.dataCadastro}">
						<f:convertDateTime pattern="HH:mm'h'" />
					</h:outputText>
				</p:column>
				
				<p:column headerText="Tipo de solicitação" sortBy="#{item.tipoSolicitacao.descricao}">
					<h:outputText value="#{item.tipoSolicitacao.descricao}" />
				</p:column>
				
				<p:column headerText="Teor" style="text-align: center;">
					<p:commandButton value="Mostrar" update=":viewForm:teorDlgDisplay" action="#{solicitacaoSetorBean.preencherVO}" oncomplete="teorDlg.show();" process="@this">
						<f:setPropertyActionListener value="#{item}" target="#{solicitacaoSetorBean.item}" />
					</p:commandButton>
				</p:column>
				
				<p:column headerText="Homologação" sortBy="#{empty item.aval}" style="text-align: center;">
					<p:commandButton value="Homologar" rendered="#{empty item.aval}" update=":viewForm:avalDlgDisplay" action="#{solicitacaoSetorBean.preencherVO}" oncomplete="avalDlg.show();" process="@this">
						<f:setPropertyActionListener value="#{item}" target="#{solicitacaoSetorBean.item}" />
					</p:commandButton>
					
					<p:commandButton value="Alterar" rendered="#{not empty item.aval}" update=":viewForm:avalDlgDisplay" action="#{solicitacaoSetorBean.preencherVO}" oncomplete="avalDlg.show();" process="@this">
						<f:setPropertyActionListener value="#{item}" target="#{solicitacaoSetorBean.item}" />
					</p:commandButton>
				</p:column>
			</p:dataTable>
			
			<p:dialog id="teorDlg" header="Teor da solicitação" widgetVar="teorDlg" modal="true" width="460" height="340">
				<h:panelGrid id="teorDlgDisplay">
					<h:outputText value="#{solicitacaoSetorBean.itemVO.descricao}" escape="false" />
				</h:panelGrid>
			</p:dialog>
			
			<p:dialog id="avalDlg" header="Homologar Solicitação" widgetVar="avalDlg" modal="true">
				<h:panelGrid id="avalDlgDisplay">
					<h:outputText value="Servidor: #{solicitacaoSetorBean.itemVO.servidor}" />
					<h:outputText value="Matrícula: #{solicitacaoSetorBean.itemVO.matriculaServidor}" /><br />
					<p:editor value="#{solicitacaoSetorBean.itemVO.aval}" /><br />
					<p:commandButton value="Atualizar" update="viewForm,avalDlgDisplay" action="#{solicitacaoSetorBean.atualizar}" onsuccess="avalDlg.hide();" process="avalDlgDisplay" />
				</h:panelGrid>
			</p:dialog>
			
			<p:poll interval="4" listener="#{solicitacaoSetorBean.atualizarItens}" update="viewTable" async="true"/>
		</h:form>
	</ui:define>
	
</ui:composition>